﻿using ExcelConfig.Config;
using SanlieHash.Fast;
using System;
using System.Collections.Generic;

namespace afirewall.core
{
    public class AfirewallAuthMap
    {
        public Dictionary<string, string[]> tagmaps = new Dictionary<string, string[]>();
        public Dictionary<string, string> passmaps = new Dictionary<string, string>();

        public AfirewallAuthMap()
        {
        }
        public void LoadAccounts(AppConfigStreamFile config, string[] accounts, string[] pass)
        {
            if (accounts.Length != pass.Length) throw new ArgumentException();
            for(int i = 0; i < accounts.Length; i++)
            {
                var key = FastGuoMi.GetSM3(accounts[i]);
                tagmaps[key] = config.Array(accounts[i]);
                passmaps[key] = FastGuoMi.EncryptSM4(key, pass[i]);
            }
        }
        internal IEnumerable<string> LoopFirewallTags(string key)
        {
            if(tagmaps.ContainsKey(key))
            foreach (var tag in tagmaps[key]) yield return tag;
        }
    }
}
